<!--Generate by Kevin's CodeBuilder 2021-09-12 16:09:23-->
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title></title>
    <head th:replace="source::header">
    </head>
</head>
<body>
    <div id="k_page_erea" class="form_main_wrap">
        <div class="k_form_grid">
            <table id="datagrid"></table>
        </div>
        <div class="k_form_condition" style="padding:12px 14px;">
            <table class="k_form_table" id="k_form_query_wrap">
                <tr>
                    <td style="width: 100px" class="label">[(${Lang.common_query_from})]</td>
                    <td style="width: 250px">
                        <input id="keywords" name="keywords" placeholder="账号/名称" class="form_input form_input90" type="text" />
                    </td>
                    <td>
                        <input id="userOrg" placeholder="请选择机构" type="text" style="min-width: 300px" />
                    </td>
                </tr>
                <tr>
                    <td colspan="3">
                         <span style="padding-left:50px">
								<button class="k_common_button" id="search_btn">
									<i class="fa fa-search"></i>
									[(${Lang.common_search})]
								</button>
						 </span>
                    </td>
                </tr>
            </table>
        </div>
    </div>
    </div>
    <script type="application/javascript" th:inline="javascript">
         var curdObj,
             height = 430,
             gridOpts = [(${dataGridJson})],//获取datagrid配置json
             title = "[(${Lang.user_windowTitle})]";//国际化语言
             gridOpts.title = title;

         $B.DomUtils.onDomLoaded(function () {

             new $B.Combox("userOrg", {
                 url: $B.getHttpHost()+"org/getUserOrgs",
                 isTree:true,
                 readOnly: true,
                 valueModel:'childId'
             });

             var dg =  document.getElementById("datagrid");
             //设置查询参数
             gridOpts.setParams = function(){
                 let $org = document.getElementById("userOrg_input");
                 let prs = {
                     keywords : document.getElementById("keywords").value,
                     orgId: $B.Dom.attr($org,"_id")
                 };
                 console.log(prs);
                 return prs;
             };
             gridOpts.title = "";
             gridOpts.pageArea = "k_page_erea";
             gridOpts.fit2height = true;
             gridOpts.oprColWidth = 325;
             gridOpts.onCreateCheckbox = function(td,data){
                 if(data.id === "0"){
                    $B.DomUtils.addClass(td.firstChild,"k_table_chk_disabled");
                 }
             };
             curdObj = new $B.CURD(dg, gridOpts);

             //输入框绑定清理按钮
             $B.bindInputClear("k_form_query_wrap");

             $B.DomUtils.click(document.getElementById("search_btn"),()=>{
                  curdObj.reload();
             });
         });
         //打开form.html
        function _openForm(prs,isUpdate,winTitle){
             console.log(prs,isUpdate,winTitle);
             var opts = {
                 dataType:'html',
                 title:winTitle ? winTitle:title,
                 width:750,
                 height:height
             };
             if(prs){
                 opts.params = prs;
             }
             curdObj.window(opts,isUpdate);
         };
         /******工具栏事件集合******/
         window.buttonEvents = {
             addFn:function(prs){
                 _openForm(undefined,false,'[(${Lang.common_add_title})]');
             },
             updateFn:function(prs){
                 _openForm(undefined,true,'[(${Lang.common_update_title})]');
             },
             deleteFn:function(prs){
                 curdObj.delChecked();
             },
             lineUpdateFn:function(prs){
                 _openForm({id:prs.id},true,'[(${Lang.common_update_title})]');
             },
             lineDeleteFn:function(prs){
                 curdObj.deleteData([prs.id]);
             },
             mutilPwdFn:function (prs) {
                 var ids = curdObj.getCheckedId();
                 if(ids.length === 0){
                     $B.alert("请选择需要重置密码的用户",1.2);
                     return;
                 }
                 ids = ids.join(";");
                 var html = $B.DomUtils.createEl("<div><p style='line-height:35px;padding-top:12px;padding-left:14px;'><span>请输入密码：</span><input autocomplete='off' id='_repwd'  type='password' style='width:220px'/></p><p style='line-height:35px;padding-top:12px;padding-left:14px;'><span>请确认密码：</span><input autocomplete='off' id='_surepwd'  type='password' style='width:220px'/></p><p  style='text-align: center;color: red;'></p></div>");
                 console.log(html);
                 var $msg = html.lastChild;
                 var $pwd =$B.DomUtils.findbyId(html,"#_repwd");
                 $B.DomUtils.input($pwd,()=>{
                     $msg.innerText = "";
                 });
                 var $surepwd = $B.DomUtils.findbyId(html,"#_surepwd");
                 $B.DomUtils.input($surepwd,()=>{
                     $msg.innerText = "";
                 });
                 var $w = $B.window({
                     iconCls:'fa-expeditedssl',
                     title:'批量重置密码',
                     fixed :true,
                     width:450,
                     height:200,
                     autoHeight:false,
                     content:html,
                     onClosed:()=>{

                     },
                     toolbar:[{
                         iconCls:'fa-ok-circle',
                         text:'确认',
                         click:function(e){
                             var newPwd = $B.trimFn($pwd.value);
                             if(newPwd === ""){
                                 //$B.alert("密码不能为空！",1.2);
                                 $msg.innerText = "密码不能为空！";
                                 return;
                             }
                             if(!$B.config.verify.password.reg.test(newPwd)){
                                 $msg.innerText = $B.config.verify.password.label;
                                 return;
                             }
                             if($surepwd.value !== newPwd){
                                 $msg.innerText = "前后密码不一致！";
                                 return;
                             }
                             $B.request({
                                 data:{
                                     userId : ids,
                                     oldpwd : "" ,
                                     newpwd : newPwd ,
                                     needOldpwd : false
                                 },
                                 url:$B.getHttpHost(ctxPath)+"user/repasswd?cmd=update",
                                 ok:function(){
                                     $B.success('[(${Lang.common_saveSucess})]',1.2);
                                     $w.close();
                                 }
                             },this);
                         }
                     }]
                 });
             },
             roleUpdateFn:function (prs) {
                  var $w =  $B.window({
                        title:'配置角色['+prs.userName+']',
                        width:600,
                        height:400,
                        url:$B.getHttpHost()+"user/page/role?userId="+prs.id,
                        onClosed:()=>{
                            window.saveUserRoleFn = undefined;
                        },
                        toolbar:[{
                            iconCls:'fa-ok-circle',
                            text:'保存',
                            click:function(e){
                                window.saveUserRoleFn(this,$w);
                            }
                        },{
                            iconCls:' fa-forward-1',
                            text:'取消',
                            click:function(e){
                                $w.close();
                            }
                        }]
                    });
             }
         };
         function formatOrg(cval,rval){
             if(rval.extFeildsMap.orgName){
                 return rval.extFeildsMap.orgName;
             }
         }

         function switchEnable(name,val,oldVal,oldClazz){
             let childs = $B.DomUtils.children(this,"span");
             let $input = this.lastChild;
             let id =  $B.DomUtils.attribute($input,"dataid");
             $B.request({
                 waiting:true,
                 url : $B.getHttpHost(ctxPath) + "user/status?cmd=update",
                 data:{id:id,status:val},
                 fail:function () {
                     for(let i =0 ; i < childs.length ; i++){
                         $B.DomUtils.attribute(childs[i],oldClazz[i]);
                     }
                     $input.value = oldVal;
                 },
                 ok:function () {
                     $B.success("修改成功！",1.6);
                 }
             });
         }

         function formatStatus(cval,rval){
             if(rval.id === "0"){
                 return "<span style='color:green'>正常</span>";
             }
             let $wap = this.firstChild.firstChild;
             let $in = $B.DomUtils.createEl('<input dataid="'+rval.id+'" id="mstatus" name="mstatus" value="'+cval+'" type="hidden">');
             $B.DomUtils.append($wap,$in);
             $B.switchCtl( $in,{
                 trueText:"正常",
                 falseText:"禁用",
                 notReturn:true,
                 onChange:switchEnable
             });
             return false;
         }
    </script>
</body>
</html>
